<?php

class usrprofile_model extends CI_Model {

    function __construct() {
        parent::__construct();
        $this->tableName = "usr_profile";
    }

    function insert($mpa_id_alumni, $nis, $name, $tempatlahir, $tanggallahir,
        $gender, $graduateyear, $phone, $email, $up_address, $city_id,
        $province_id, $up_zipcode, $up_status, $up_picture,
        $up_father, $up_mother, $up_home_phone, $up_home_address, $up_home_city_id,
        $up_home_province_id) {

        
        $dt = array("mpa_id_alumni" => $mpa_id_alumni,
            "up_nis" => $nis,
            "up_fullname" => $name,
            "up_display_name" => $name,
            "up_birth_place" => $tempatlahir,
            "up_birth_date" => $tanggallair,
            "up_gender" => $gender,
            "up_graduate_year" => $graduateyear,
            "up_phone" => $phone,
            "up_email" => $email,
            "up_address" => $up_address,
            "city_id" => $city_id,
            "province_id" => $province_id,
            "up_zipcode" => $up_zipcode,
            "up_status" => $up_status,
            "up_picture" => $up_picture,
            "up_father" => $up_father,
            "up_mother" => $up_mother,
            "up_home_phone" => $up_home_phone,
            "up_home_address" => $up_home_address,
            "up_home_city_id" => $up_home_city_id,
            "up_home_province_id" => $up_home_province_id,
            "up_home_zipcode" => $up_home_zipcode);
        $this->db->insert($this->tableName, $dt);
        return $this->db->insert_id();
    }

    function update($mpa_id_alumni, $dt, $where = "") {
        $this->db->where("mpa_id_alumni", $mpa_id_alumni);
        if ($where != "")
            $this->db->where($where);
        $this->db->update($this->tableName, $dt);
    }

    function delete($mpa_id_alumni, $where = "") {
        $this->db->where("mpa_id_alumni", $mpa_id_alumni);
        if ($where != "")
            $this->db->where($where);
        $this->db->delete($this->tableName);
    }

    function getById($mpa_id_alumni, $where = "") {
        $this->db->select("*")->from($this->tableName);
        $this->db->where($this->tableName . ".mpa_id_alumni", $mpa_id_alumni);
        if ($where != "")
            $this->db->where($where);
        return $this->db->get()->row();
    }

    function getAll($startpage = "0", $perpage = "10", $where = "", $like="", $orderby = "") {
        if ($where != "")
            $this->db->where($where);
        $this->db->limit($perpage, $startpage);
        if ($orderby != "")
            $this->db->order_by($orderby);
        if ($like != "")
            $this->db->like($like);
        return $this->db->get($this->tableName)->result();
    }

    function getAllCount($where = "", $like="") {
        $this->db->select("COUNT(*) JUMLAH");
        $this->db->from($this->tableName);
        if ($where != "")
            $this->db->where($where);
        if ($like != "")
            $this->db->like($like);
        return $this->db->get()->row()->JUMLAH;
    }

    function getAllProfile($startpage = "0", $perpage = "10", $where = "", $like="", $orderby = "") {
        $this->db->from($this->tableName)
             ->join("usr_account", $this->tableName . ".mpa_id_alumni = usr_account.mpa_id_alumni")
             ->join("master_profile_alumni", $this->tableName . ".mpa_id_alumni = master_profile_alumni.mpa_id_alumni");
        if ($where != "")
            $this->db->where($where);
        $this->db->limit($perpage, $startpage);
        if ($orderby != "")
            $this->db->order_by($orderby);
        if ($like != "")
            $this->db->like($like);
        return $this->db->get()->result();
    }

    function getAllProfileCount($where = "", $like="") {
        $this->db->select("COUNT(*) JUMLAH");
        $this->db->from($this->tableName)
             ->join("usr_account", $this->tableName . ".mpa_id_alumni = usr_account.mpa_id_alumni")
             ->join("master_profile_alumni", $this->tableName . ".mpa_id_alumni = master_profile_alumni.mpa_id_alumni");   
        if ($where != "")
            $this->db->where($where);
        if ($like != "")
            $this->db->like($like);
        return $this->db->get()->row()->JUMLAH;
    }
    
    function updatePicture($mpa_id_alumni, $picture) {
        $this->db->update($this->tableName, array('up_picture' => $picture), array('mpa_id_alumni' => $mpa_id_alumni));
        log_message('debug', $this->db->last_query());
    }

}

?>